using System;
using System.Collections.Generic;
using System.Text;
using Fan.Dongping.DataBase;
using System.Data.SqlClient;
using System.Data;

namespace Fan.Dongping.DataAccess
{
    public class UserDefinedColumnDA
    {
        public static string GetDocColumnTitle(string workflowNo, string itemNo, string columnName)
        {
            string sql = "select fld_nam from jkkb31_det_nam where flw_no =@workflowNo and item_no=@itemNo and fld_no=@columnName";
            SqlParameter[] paras = new SqlParameter[3];
            paras[0] = new SqlParameter("@workflowNo", workflowNo);
            paras[2] = new SqlParameter("@itemNo", itemNo);
            paras[3] = new SqlParameter("@columnName", columnName);


            object o = DA_Base.ExecuteScalar(sql, paras);
            if (o == null)
            {
                return columnName;
            }
            else
            {
                return o as string;
            }
        }

        public static string GetDocColumnTitle(string workflowNo, string columnName)
        {
            string sql = "select fld_nam from jkkb31_det_nam where flw_no =@workflowNo and fld_no=@columnName";
            SqlParameter[] paras = new SqlParameter[3];
            paras[0] = new SqlParameter("@workflowNo", workflowNo);
            paras[1] = new SqlParameter("@columnName", columnName);


            object o = DA_Base.ExecuteScalar(sql, paras);
            if (o == null)
            {
                return columnName;
            }
            else
            {
                return o as string;
            }
        }

        public static DataTable GetDocColumnTitles(string workflowNo)
        {
            string sql = "select * from jkkb31_det_nam where flw_no =@workflowNo";
            SqlParameter[] paras = new SqlParameter[1];
            paras[0] = new SqlParameter("@workflowNo", workflowNo);

            return DA_Base.RunReturnDataset(sql, paras).Tables[0];

        }

        public static DataTable GetSubDocColumnTitles(string workflowNo)
        {
            string sql = "select * from jkkb35_det2_nam where flw_no =@workflowNo";
            SqlParameter[] paras = new SqlParameter[1];
            paras[0] = new SqlParameter("@workflowNo", workflowNo);
            // paras[1] = new SqlParameter("@columnName", columnName);

            return DA_Base.RunReturnDataset(sql, paras).Tables[0];
  
        }

    }
}
